package com.wz.datachannel.app;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.WZAccessServiceManager;
import android.os.WZBubbleUserInfo;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.WindowManager;

public class LocalData {
	public static String IMEI;
	public static int ID;
	public static int WIDTH, HEIGHT, DENSITYDPI;
	public static float DENSITY;
	public static int VERSION;
	public static String VERSION_NAME;
	public static String TAG;
	public static String SYS_VERSION_NAME;
	public static int SYS_VERSION;
	public static String userId;
	public static String userPasswd;

	public static void init(Context context) {
		TelephonyManager TelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
		IMEI = TelephonyMgr.getDeviceId();
		DisplayMetrics metric = new DisplayMetrics();
		WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		wm.getDefaultDisplay().getMetrics(metric);
		WIDTH = metric.widthPixels; // 屏幕宽度（像素）  
		HEIGHT = metric.heightPixels; // 屏幕高度（像素）  
		DENSITY = metric.density; // 屏幕密度（0.75 / 1.0 / 1.5）  
		DENSITYDPI = metric.densityDpi;
		PackageManager pm = context.getPackageManager();
		PackageInfo pi;
		TAG = context.getPackageName();
		try {
			pi = pm.getPackageInfo(TAG, 0);
			VERSION_NAME = pi.versionName;
			VERSION = pi.versionCode;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		SYS_VERSION = Build.VERSION_CODES.JELLY_BEAN_MR1;
		SYS_VERSION_NAME = Build.HARDWARE;
		isUserInfoValid();
	}

	/**
	 * 用户信息是否有效
	 * @author wei 
	 * @return
	 */
	public static boolean isUserInfoValid() {
		if (TextUtils.isEmpty(userId) || TextUtils.isEmpty(userPasswd)) {
			try {
				WZBubbleUserInfo userInfo = WZAccessServiceManager.getBubbleUserFullInfo();
				userId = userInfo.getUserID();
				userPasswd = userInfo.getPassword();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return !TextUtils.isEmpty(userId) && !TextUtils.isEmpty(userPasswd);
	}
}
